package com.xintonghua.bussiness.adapter;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xintonghua.base.adapter.BaseAdapter;
import com.xintonghua.base.utils.MyUtils;
import com.xintonghua.bussiness.BuildConfig;
import com.xintonghua.bussiness.R;
import com.xintonghua.bussiness.bean.CollectBean;
import com.xintonghua.bussiness.ui.fragment.college.H5Activity;
import com.xintonghua.bussiness.util.GlideUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 作者：wanxianyi
 * 时间：2018/1/11.
 * 包名：com.xintonghua.bussiness.adapter
 */

public class CollegeAdapter extends BaseAdapter<CollectBean, CollegeAdapter.CollegeViewHolder> {


    public CollegeAdapter(Activity mActivity, List<CollectBean> list) {
        super(mActivity, list);
    }

    @Override
    public CollegeViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.adapter_college, parent, false);
        return new CollegeViewHolder(view);
    }

    @Override
    public void onBindViewHolder(CollegeViewHolder holder, int position) {
        final CollectBean bean = list.get(position);
        GlideUtils.load(mActivity, holder.ivImage, bean.getImg(), R.drawable.culture_pic);
        holder.tvTitle.setText(bean.getTitle());
        holder.rlCollect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle = new Bundle();
                bundle.putParcelable(BuildConfig.FLAVOR, bean);
                MyUtils.openActivity(mActivity, H5Activity.class, bundle);
            }
        });
    }


    class CollegeViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_image)
        ImageView ivImage;
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.rl_collect)
        RelativeLayout rlCollect;

        public CollegeViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
